# -*- coding:utf-8 -*-
# __auther__='jiangkai'

import selenium.webdriver
from selenium.webdriver.support.ui import Select
from time import sleep
import os
from extScript.UploadPic import UploadPic


class HY:
    def __init__(self):
        pass

    def test_hy(self, driver, dist=None):
        Select(driver.find_element_by_id("immovablesClass")).select_by_visible_text(u"海域使用权")
        driver.find_element_by_id("immovablesDetail").clear()
        driver.find_element_by_id("immovablesDetail").send_keys(dist["不动产具体描述"])
        Select(driver.find_element_by_id("immovablesGetWay")).select_by_visible_text(dist["不动产取得方式"])

        driver.find_element_by_id("immovablesLoc").clear()
        driver.find_element_by_id("immovablesLoc").send_keys(dist["不动产坐落"])
        driver.find_element_by_id("immovablesArea").clear()
        driver.find_element_by_id("immovablesArea").send_keys(dist["面积"])

        if dist["证件类型"] == "不动产证号":
            driver.find_element_by_id("immovablesNo").clear()
            driver.find_element_by_id("immovablesNo").send_keys(dist["不动产证号"])
        else:
            driver.find_element_by_id("seaNo").clear()
            driver.find_element_by_id("seaNo").send_keys(dist['权证编号'])

        Select(driver.find_element_by_id("circulationType3")).select_by_visible_text(dist['流转性质'])

        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("immovablesLoc"))
        sleep(1)
        driver.find_element_by_xpath("/html/body/content/div[1]/form/div/div[15]/div[3]/div[3]/input").click()
        driver.find_element_by_xpath("/html/body/content/div[1]/form/div/div[15]/div[3]/div[3]/input").send_keys(
            str(dist["开始时间"])[0:10])
        driver.find_element_by_xpath("/html/body/content/div[1]/form/div/div[15]/div[3]/div[5]/input").click()
        driver.find_element_by_xpath("/html/body/content/div[1]/form/div/div[15]/div[3]/div[5]/input").send_keys(
            str(dist["截止时间"])[0:10])
        driver.find_element_by_xpath("/html/body/content/div[1]/form/div/div[15]/div[5]/div[1]").click()

        driver.find_element_by_id("boundary").clear()
        driver.find_element_by_id("boundary").send_keys(dist["界址"])

        driver.find_element_by_id("copy18").click()

        UploadPic(driver, "/html/body/content/div[1]/form/div/div[15]/div[6]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["转让协议电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[15]/div[6]/div[3]/div[1]/div[1]/div[2]/a")

        sleep(1)
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("boundary"))
        driver.find_element_by_id("copy19").click()
        sleep(1)
        UploadPic(driver, "/html/body/content/div[1]/form/div/div[15]/div[9]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["使用权证书电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[15]/div[9]/div[3]/div[1]/div[1]/div[2]/a")

        sleep(2)
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_xpath(
            '/html/body/content/div[1]/form/div/div[15]/div[6]/div[3]/div[1]/div[1]/div[2]/div/input'))
        driver.find_element_by_id("copy20").click()

        UploadPic(driver, "/html/body/content/div[1]/form/div/div[15]/div[12]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["所有权证明材料电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[15]/div[12]/div[3]/div[1]/div[1]/div[2]/a")

        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("copy19"))
        sleep(1)
        driver.find_element_by_id("copy21").click()
        sleep(1)
        driver.find_element_by_id("copy22").click()
        sleep(1)

        UploadPic(driver, "/html/body/content/div[1]/form/div/div[15]/div[16]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["主管部门电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[15]/div[16]/div[3]/div[1]/div[1]/div[2]/a")

        sleep(3)
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("copy20"))
        driver.find_element_by_id("copy23").click()

        UploadPic(driver, "/html/body/content/div[1]/form/div/div[15]/div[19]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["转让的书面意见电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[15]/div[19]/div[3]/div[1]/div[1]/div[2]/a")

        sleep(2)
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_xpath(
            "/html/body/content/div[1]/form/div/div[15]/div[16]/div[3]/div[1]/div[1]/div[2]/div/input"))

        driver.find_element_by_name("interestedPartyView").click()
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        sleep(1)

        # 选择利害关系人意见证明材料上传
        UploadPic(driver, "/html/body/content/div[1]/form/div/div[18]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["利害关系人意见证明材料"]).upfile(
            "/html/body/content/div[1]/form/div/div[18]/div[3]/div[1]/div[1]/div[2]/a")
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        sleep(1)

        driver.find_element_by_id("textarea2").clear()
        driver.find_element_by_id("textarea2").send_keys(dist["备注"])
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        driver.find_element_by_id("next-step2").click()


if __name__ == '__main__':
    a = HY()
    a.test_hy()
